package org.example.fronted.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.entity.Goods;
import org.example.fronted.mapper.GoodMapper;
import org.example.fronted.service.FrontedGoodService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Service
public class FrontedGoodServiceImpl implements FrontedGoodService {
    @Value("${imageServer}")
    private String imageServerLocation;

    @Resource
    private GoodMapper goodMapper;

    @Override
    public List<Goods> setGoodsByIds(Integer[] ids) {
//        List<Goods> list = goodMapper.selectBatchIds(Arrays.asList(ids));
        QueryWrapper<Goods> wrapper = new QueryWrapper();
        List<Goods> list = goodMapper.selectList(wrapper.in("goods_id", Arrays.asList(ids)));
        list.forEach(g -> {
            String smallPic = g.getSmallPic();
            g.setSmallPic(imageServerLocation + smallPic);
        });
        return list;
    }
}
